// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import sessionStorage from "./assets/js/storage";
import {getWebTitle} from "./api/web-site";

Vue.use(ElementUI)
/* eslint-disable no-new */

router.beforeEach((to, from, next) => {
  let user = JSON.parse(sessionStorage.getItem('usrId'));
  if (!user && to.path !== '/') {
    if(to.path === '/orderIndex'){
      getWebTitle(to)
      next();
    }else if(to.path === '/changePass'){
      getWebTitle(to)
      next();
    }else if(to.path === '/registerIndex'){
      getWebTitle(to)
      next();
    }else {
      getWebTitle(to)
      sessionStorage.clear()
      next({
        path: '/'
      })
    }
  }  else {
    getWebTitle(to)
    next();
  }
})
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
